package com.qf.openapi.web.master.controller;

import cn.hutool.crypto.digest.DigestUtil;
import com.qf.openapi.web.master.entity.User;
import com.qf.openapi.web.master.service.UserService;
import com.qf.openapi.web.master.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户id查询用户
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public User getUser(@PathVariable("id") Integer id){
        System.out.println("sjadiajsdiqwe");
        return userService.getUser(id);
    }
    @ResponseBody
    @RequestMapping("/get1")
    public String getUser(@RequestBody UserVo userVo, HttpServletRequest req, HttpServletResponse resp){

        String code = (String) req.getSession().getAttribute("captcha");

        String s = code.toLowerCase();
        String s1 = userVo.getCaptchar().toLowerCase();

        if (s.equals(s1)){
            //验证码正确  继续验证用户名密码
            User user = userService.login(userVo);
            if (user!=null){
                return "0";
            }else {
             return "1";
            }
        }else {
            return "2";
        }

    }
    
    
    
}
